package com.itheima.store.service.impl;

import java.sql.SQLException;
import java.util.List;

import com.itheima.store.dao.BookBorrowDao;
import com.itheima.store.dao.BookBorrowItemsDao;
import com.itheima.store.domain.BookBorrow;
import com.itheima.store.domain.BookBorrowItems;
import com.itheima.store.domain.PageBean;
import com.itheima.store.domain.SystemSetting;
import com.itheima.store.service.BookBorrowItemsService;
import com.itheima.store.utils.BeanFactory;

public class BookBorrowItemsServiceImpl implements BookBorrowItemsService {

	@Override
	public String save(BookBorrowItems bbi) throws SQLException {
		BookBorrowItemsDao bbid =(BookBorrowItemsDao)BeanFactory.getBean("bookBorrowItemsDao");
		return bbid.addBookBorrow(bbi);
		
	}

	@Override
	public PageBean<BookBorrowItems> findByUserId(String user_id, Integer currPage) throws SQLException {
		PageBean<BookBorrowItems> pageBean = new PageBean<BookBorrowItems>();
		// 设置参数：
		// 设置当前页数：
		pageBean.setCurrPage(currPage);
		// 设置每页显示的记录数:
		Integer pageSize = 10;
		pageBean.setPageSize(pageSize);
		// 设置总记录数:
		BookBorrowItemsDao bbid =(BookBorrowItemsDao)BeanFactory.getBean("bookBorrowItemsDao");
		Integer totalCount = bbid.findCountByUserId(user_id);
		pageBean.setTotalCount(totalCount);
		// 设置总页数:
		double tc = totalCount;
		Double num = Math.ceil(tc / pageSize);
		pageBean.setTotalPage(num.intValue());
		// 设置每页显示的数据的集合:
		int begin = (currPage - 1) * pageSize;
		List<BookBorrowItems> list = bbid.findPageByUserId(user_id,begin,pageSize);
		pageBean.setList(list);
		return pageBean;
	}

	@Override
	public List<BookBorrow> findByOid(String oids) throws SQLException {
		BookBorrowItemsDao bbid =(BookBorrowItemsDao)BeanFactory.getBean("bookBorrowItemsDao");
		return bbid.findByOid(oids);
	}

	@Override
	public List<SystemSetting> findSetting() throws SQLException {
		BookBorrowItemsDao bbid =(BookBorrowItemsDao)BeanFactory.getBean("bookBorrowItemsDao");
		return bbid.findSetting();
		
	}

	

	

}
